package com.example.mapp;

import com.example.entity.supervision.CheckResult;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;

import java.util.List;
import java.util.Map;

/**
 * Created by simon on 2018/8/7.
 */
@Mapper
public interface CheckResultMapp {

    @Insert(" insert into check_result (scrid,pditemid,result,ext1,ext2,device_num,device_name,enforcement_code) " +
            " value (#{scrid},#{pditemid},#{result},#{ext1},#{ext2},#{deviceNum},#{deviceName},#{enforcementCode})")
    @SelectKey(statement = "select last_insert_id()", keyProperty = "id", keyColumn = "id", before = false, resultType = Long.class)
    int insert(CheckResult checkResult) throws Exception;

    @Select(" select a.result,c.item_type as itemType,c.item_name as itemName ," +
            " c.item_no as itemNo,c.item_content as itemContent,c.is_use as isUse, c.id " +
            " from check_result a" +
            " left join check_item c on a.pditemid = c.id where a.scrid = #{scrid} ")
    List<Map> query(Map map) throws Exception;

    /**
     * 查询某个检查记录中未通过的检查项
     */
    @Select("select C.id,D.code,C.item_content as itemContent,A.device_name as deviceName ,A.device_num as deviceNum," +
            "C.item_content as itemContent,D.violation_laws as violationLaws,D.violation_laws_content as violationLawsContent," +
            "D.law_enforcement_basis as lawEnforcementBasis,D.law_enforcement_basis_content as lawEnforcementBasisContent,D.treatment_measures as treatmentMeasures" +
            " from check_result A\n" +
            "    left join check_item C ON A.pditemid = C.id\n" +
            "    left join low_code_mapping D on A.enforcement_code = D.code where A.result = 0 and A.scrid = #{id}")
    List<Map> queryCheckResult(String id) throws Exception;

}
